package bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;

/**
 * @author DJJ_F
 * @version 1.0
 * @date 2024/11/28
 * @description
 */
public class Person implements BeanNameAware, BeanClassLoaderAware, BeanFactoryAware, InitializingBean, DisposableBean {
    private String name;
    public Person() {
        System.out.println("1. Person的无参构造方法执行了");
    }


    public void setName(String name) {
        System.out.println("2. set方法赋值");
        this.name = name;
    }
    public void beanInit() {
        System.out.println("6. bean的初始化");
    }
    public void beanDestroy() {
        System.out.println("10. bean的销毁");
    }

    @Override
    public void setBeanClassLoader(ClassLoader classLoader) {
        System.out.println("   属性赋值后，bean后处理器的before方法前");
        System.out.println("\t\t可获取bean的类加载器: " + classLoader);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("   属性赋值后，bean后处理器的before方法前");
        System.out.println("\t\t可获取bean的工厂: " + beanFactory);
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("3. 属性赋值后，bean后处理器的before方法前");
        System.out.println("\t\t可获取bean的名字: " + name);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("5. bean后处理器before()后，初始化前");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("9. 销毁前执行");
    }
}
